In [1]:
1+1
Out[1]:
some more code blocks...
In [6]:
import numpy as np
In [15]:
eps=1e-10
In [16]:
def precision(v,p):
v=np.array(v)
p=np.array(p)
tpa=[pred*int(eq) for (pred,eq) in zip(p,np.equal(v,p))]
fpa=[pred*int(not eq) for (pred,eq) in zip(p,np.equal(v,p))]
tp=sum(tpa)
fp=sum(fpa)
return tp/(fp+tp+eps)
In [17]:
def recall(v,p):
v=np.array(v)
p=np.array(p)
tpa=[pred*int(eq) for (pred,eq) in zip(p,np.equal(v,p))]
fna=[(1-pred)*int(not eq) for (pred,eq) in zip(p,np.equal(v,p))]
tp=sum(tpa)
fn=sum(fna)
return tp/(fn+tp+eps)
In [18]:
def f2(a,b):
pc=precision(a,b)
rc=recall(a,b)
return 5 * pc * rc / ((4*pc) + rc + eps)
In [19]:
a=[1,1,0,1,1]
b=[1,1,1,0,0]
f2(a,b)
Out[19]:
In [20]:
2+2
Out[20]:
In [ ]: